package com.yesstech.generate.document.controller;

import com.yesstech.generate.document.service.GenerateDocumentService;
import com.yesstech.generate.document.vo.GenerateDocumentVo;
import io.github.swagger2markup.markup.builder.MarkupLanguage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 文档生成
 *
 * @author pengzhikang
 * @date 2025/3/12 16:48
 * @since 1.0.0
 */
@Api(tags = "文档生成")
@RestController()
@RequestMapping("/generateDocument")
public class GenerateDocumentController {

    @Autowired
    private GenerateDocumentService generateDocumentService;

    @ApiOperation("generate AsciiDocs")
    @PostMapping("/generateAsciiDocs")
    public void generateAsciiDocs(@RequestBody GenerateDocumentVo generateDocumentVo, HttpServletResponse response) {
        generateDocumentVo.setMarkupLanguage(MarkupLanguage.ASCIIDOC);
        generateDocumentVo.setFileName("asciidoc");

        generateDocumentService.generateDocument(generateDocumentVo, response);
    }

    @ApiOperation("generate Markdown")
    @PostMapping("/generateMarkdown")
    public void generateMarkdown(@RequestBody GenerateDocumentVo generateDocumentVo, HttpServletResponse response) throws IOException {
        generateDocumentVo.setMarkupLanguage(MarkupLanguage.MARKDOWN);
        generateDocumentVo.setFileName("markdown");

        generateDocumentService.generateDocument(generateDocumentVo, response);
    }

    @ApiOperation("generate Confluence")
    @PostMapping("/generateConfluence")
    public void generateConfluence(@RequestBody GenerateDocumentVo generateDocumentVo, HttpServletResponse response) throws IOException {
        generateDocumentVo.setMarkupLanguage(MarkupLanguage.CONFLUENCE_MARKUP);
        generateDocumentVo.setFileName("txt");

        generateDocumentService.generateDocument(generateDocumentVo, response);
    }
}
